package cn.edu.hbwe.book.servlet.book;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hbwe.book.entity.Notice;
import cn.edu.hbwe.book.service.book.BookService;
import cn.edu.hbwe.book.service.notice.NoticeService;


/**
 * Servlet implementation class ShowIndexServlet
 */
@WebServlet("/ShowIndexServlet")
public class ShowIndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//查询最近一条公告，传递到index.jsp页面进行展示
		NoticeService nService = new NoticeService();
				Notice notice = nService.getRecentNotice();
				request.setAttribute("n", notice);
				
				//查询本周热销的两条商品，传递到index.jsp页面进行展示
				BookService pService = new BookService();
				List<Object[]> pList =  pService.getWeekHotProduct();
				/*for(Object[] os:pList){
					for(Object o:os){
						System.out.println(o);
					}
					System.out.println("---------------------");
				}*/
				request.setAttribute("pList", pList);
				
				//请求转发
				request.getRequestDispatcher("/client/index.jsp").forward(request, response);
	}

}
